<?php

/**
 * Landmark filter form base class.
 *
 * @package    lbreminder
 * @subpackage filter
 * @author     Your name here
 */
abstract class BaseLandmarkFormFilter extends BaseFormFilterPropel
{
  public function setup()
  {
    $this->setWidgets(array(
      'name'               => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'latitude'           => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'longitude'          => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'address'            => new sfWidgetFormFilterInput(),
      'street'             => new sfWidgetFormFilterInput(),
      'suburb'             => new sfWidgetFormFilterInput(),
      'state'              => new sfWidgetFormFilterInput(),
      'postcode'           => new sfWidgetFormFilterInput(),
      'description'        => new sfWidgetFormFilterInput(),
      'category_id'        => new sfWidgetFormPropelChoice(array('model' => 'LandmarkCategory', 'add_empty' => true)),
      'user_landmark_list' => new sfWidgetFormPropelChoice(array('model' => 'sfGuardUser', 'add_empty' => true)),
    ));

    $this->setValidators(array(
      'name'               => new sfValidatorPass(array('required' => false)),
      'latitude'           => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'longitude'          => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'address'            => new sfValidatorPass(array('required' => false)),
      'street'             => new sfValidatorPass(array('required' => false)),
      'suburb'             => new sfValidatorPass(array('required' => false)),
      'state'              => new sfValidatorPass(array('required' => false)),
      'postcode'           => new sfValidatorPass(array('required' => false)),
      'description'        => new sfValidatorPass(array('required' => false)),
      'category_id'        => new sfValidatorPropelChoice(array('required' => false, 'model' => 'LandmarkCategory', 'column' => 'id')),
      'user_landmark_list' => new sfValidatorPropelChoice(array('model' => 'sfGuardUser', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('landmark_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    parent::setup();
  }

  public function addUserLandmarkListColumnCriteria(Criteria $criteria, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $criteria->addJoin(UserLandmarkPeer::LANDMARK_ID, LandmarkPeer::ID);

    $value = array_pop($values);
    $criterion = $criteria->getNewCriterion(UserLandmarkPeer::USER_ID, $value);

    foreach ($values as $value)
    {
      $criterion->addOr($criteria->getNewCriterion(UserLandmarkPeer::USER_ID, $value));
    }

    $criteria->add($criterion);
  }

  public function getModelName()
  {
    return 'Landmark';
  }

  public function getFields()
  {
    return array(
      'id'                 => 'Number',
      'name'               => 'Text',
      'latitude'           => 'Number',
      'longitude'          => 'Number',
      'address'            => 'Text',
      'street'             => 'Text',
      'suburb'             => 'Text',
      'state'              => 'Text',
      'postcode'           => 'Text',
      'description'        => 'Text',
      'category_id'        => 'ForeignKey',
      'user_landmark_list' => 'ManyKey',
    );
  }
}
